	
	Ext.BLANK_IMAGE_URL = "../script/ext-2.0.2/resources/images/default/s.gif"; 
	
	var authStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../util/multiParam!getMultiParam.action?dateTime='+new Date().getTime()+'&paramCode=SYS004'}),
        reader: new Ext.data.JsonReader({
            root: 'param',
            fields:["key","value"]
        }),
        remoteSort: true
    }); 
    
    authStore.load();
	
	var authSelect = new Ext.form.ComboBox({
						  id:'authValue',
						  name:'authValue',
						  fieldLabel: '授权权限',
					      hiddenName: 'auth',
					      store: authStore,
					      valueField:'key',
				          displayField:'value',
				          typeAhead: true,
				          mode: 'local',
				          triggerAction: 'all',
				          resizable:true,
				          emptyText:'请选择授权权限...',
				          allowBlank: false,
				          anchor:'95%',
				          forceSelection:true
						});
						
	var sm = new Ext.grid.CheckboxSelectionModel();
	
	var colRoleManage=new Ext.grid.ColumnModel([sm,
		{header:"角色名称",dataIndex:"roleName",width:100,sortable:true},
		{header:"授权权限",dataIndex:"auth",width:100,sortable:true}
		]);
	
	var storeRoleManage = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
        	url: 'roleInfo!getList.action?dateTime='+new Date().getTime()
        }),
        reader: new Ext.data.JsonReader({
            root: 'ZANY',
            totalProperty: "results",
            fields:["roleName","roleCode","auth"]
        }),
        sortInfo:{field:'roleCode', direction:'DESC'},// 排序信息
        remoteSort: true
    });
    
    storeRoleManage.load();
    
	var roleManage = new Ext.grid.GridPanel({
		id:'roleManage',
		title :'[角色管理]信息维护',
		height:500,
		stripeRows :true,
		bodyStyle:'width:100%',
        disableSelection:true,
		cm: colRoleManage,
		viewConfig: {
            forceFit:true
        },
		store: storeRoleManage,
		iconCls: 'details',
		animCollapse: true,
		trackMouseOver:false, 
        loadMask: {msg:'正在加载[角色管理]信息，请稍侯……'},
		selModel:sm, 
		tbar:['-',{text:'&nbsp;&nbsp;添&nbsp;&nbsp;加&nbsp;&nbsp;',iconCls:'add',handler:insertinfo},
			  '-',{text:'&nbsp;&nbsp;删&nbsp;&nbsp;除&nbsp;&nbsp;',iconCls:'remove',handler:delinfo}			  
		],
		bbar: new Ext.PagingToolbar({
	            pageSize: 20,
	            store: storeRoleManage,
	            displayInfo: true,
	        	emptyMsg:'没有记录'
	        })
	});
	
	function insertinfo(){
		winKey.show();	
    }
    
	function delinfo(){
		if (Ext.getCmp("roleManage").getSelectionModel().hasSelection()) {
			Ext.MessageBox.confirm('Message','请问您真的要删除所选数据么？',function(btn){
        	if(btn == 'yes'){	
	            var ids = new Array();
	            var records = Ext.getCmp("roleManage").getSelectionModel().getSelections();
	            for (var i = 0, len = records.length; i < len; i++) {
	                ids[i] = records[i].data["roleCode"];
	            }
	            Ext.Ajax.request({url:'roleInfo!delete.action?dateTime='+new Date().getTime(),
	                params:{delId:ids},
	                success:function(response, options){
	                   var response = Ext.util.JSON.decode(response.responseText);
						if(response.success){
					        Ext.getCmp('roleManage').getStore().reload(); //刷新Grid
	                    	ZANY.util.Msg('信息',"删除角色信息成功！");
						}else if(!response.success){
							ZANY.util.Msg('信息',"删除角色信息失败，如有问题请联系系统管理员！");  
						}             
	                }
	        	});
			}
		})}else{
			ZANY.util.Msg('提示信息',"请选择用户后再操作！");   
		}
	}
	
	function getList(){
	    storeRoleManage.load({
	    	callback : function(r, options, success) {   
		        if (success == false) {   
		            Ext.Msg.alert("错误", storeRoleManage.reader.jsonData.msg);
		        }   
		    }
		});
	}
	
	var fieldSet =  new Ext.form.FieldSet({
                autoHeight: true,
                width: 317,
                defaults: {width: 200},
		        defaultType: 'textfield',
                items: [
		                {
							fieldLabel: '角色名称',
							name: 'roleName',
							id:'roleName',
							maxLength:200,
							anchor:'95%',
							allowBlank:true
		                },
		                authSelect
		               ] 
    })
    
	var fp = new Ext.FormPanel({
						id:'ext_form',
				        labelWidth: 100, 
				        waitMsg:'正在提交，请稍后...',
				        frame:true,
				        bodyStyle:'padding:5px 5px 0',
				        width: 400,
				        reader: new Ext.data.JsonReader({
				            root: 'ZANY',
				            totalProperty: "results",
				            fields:["roleName","roleCode","auth"]
				        }),
				        items: [{
				        		 layout:'column',
							     layout: 'form',
							     defaultType: 'textfield',
							     items: [{
											fieldLabel: '角色名称',
											name: 'roleName',
											id:'roleName',
											anchor:'95%',
											allowBlank:true
						                },
						                authSelect	
								        ]
				        }] 
	    			});
	    			
	var winKey =new Ext.Window({
						id:"ext_win",
        				title: '[角色信息]',
						width: 400,
						closeAction:'hide',
						modal:true,
						iconCls: 'add',
						buttons: [{
				            text: '提交',
				            handler: function(){
				            	if(fp.form.isValid()){
				            		fp.form.submit({
					                    url: 'roleInfo!insert.action?dateTime='+new Date().getTime(),
										waitTitle:"维护角色信息",
					                    waitMsg: '正在提交数据,请稍后... ...',
					                    success: function(){
											Ext.getCmp('roleManage').getStore().reload();
											fp.form.reset();
							                storeRoleManage.modified = [];//将修改过的记录置为空，如果不清空，则修改过的数据会一直保留
											Ext.MessageBox.alert('提示信息', '维护角色信息成功！'); 
											winKey.hide();
										},
										failure:function(form,action){
											Ext.MessageBox.alert('提示信息', '维护角色信息失败,请联系系统管理员!'+action.result.msg);
										}
					                });
				            	}else{
				            		ZANY.util.Msg('添加提示','数据不完整！');
				            	}
				            }
				        },{
				            text: '取消',handler: function(){winKey.hide();fp.form.reset();}
				        }],
						items:[fp]	
					});					
	
	Ext.onReady(function(){
		Ext.QuickTips.init(); 
	　　 Ext.form.Field.prototype.msgTarget = 'side';
			var port = new Ext.Viewport({
				layout : 'fit',
				frame : true,
				items : [this.roleManage]
	    	});
	});